package com.tarena.lbs.coupon.dao.repository.impl;

import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.coupon.dao.mapper.CouponMapper;
import com.tarena.lbs.coupon.dao.repository.CouponRepository;
import com.tarena.lbs.coupon.pojo.po.CouponPO;
import com.tarena.lbs.coupon.pojo.query.UserCouponQuery;
import com.tarena.lbs.coupon.pojo.vo.UserCouponsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class CouponRepositoryImpl implements CouponRepository {
    
    @Autowired
    private CouponMapper couponMapper;
    
    @Override
    public int insert(CouponPO couponPO) {
        log.info("执行插入优惠券操作: {}", couponPO);
        int result = couponMapper.insert(couponPO);
        log.info("插入优惠券完成，影响行数: {}", result);
        return result;
    }
    
    @Override
    public int updateById(CouponPO couponPO) {
        log.info("执行更新优惠券操作: ID={}", couponPO.getId());
        int result = couponMapper.updateById(couponPO);
        log.info("更新优惠券完成，影响行数: {}", result);
        return result;
    }
    
    @Override
    public CouponPO selectById(Integer id) {
        log.info("执行查询优惠券操作: ID={}", id);
        CouponPO result = couponMapper.selectById(id);
        log.info("查询优惠券完成: ID={}, 结果={}", id, result != null ? "找到记录" : "未找到记录");
        return result;
    }

    @Override
    public PageResult<UserCouponsVO> receiveList(UserCouponQuery couponQuery) {
        return couponMapper.receiveList(couponQuery);
    }
}